/*
 * Blink.c
 *
 * Created: 11/24/2013 8:25:01 AM
 *  Author: Jovan
 */ 

// this is the header file that tells the compiler what resources (pins, ports, clocks, etc.)
// are available on our Microcontroller (MCU).
#include <avr/io.h>
// this is the header file that allows us to delay things for a while
#include <util/delay.h>

// Define what pins the LEDs are connected to.
#define LED1 PINB4 
#define LED2 PINB1


// Some macros that help us not repeat ourselves.
// This also makes the code more readable

#define output_low(port,pin) port &= ~(1<<pin)
#define output_high(port,pin) port |= (1<<pin)
#define set_input(portdir,pin) portdir &= ~(1<<pin)
#define set_output(portdir,pin) portdir |= (1<<pin)
	 		
int main(void)
{
	// set the direction of PORTD where opr the LEDs are to be an output
	set_output(DDRB, LED1);
	set_output(DDRB, LED2);

    while(1)
    {
		// turn on the LED for 200ms
		output_high(PORTB, LED1);
		_delay_ms(50);
		// now turn off the LED for another 200ms
		output_low(PORTB, LED1);
		_delay_ms(50);
        // start all over again from the top of the loop 
    		// turn on the LED for 200ms

        output_high(PORTB, LED2);
        _delay_ms(999);
        // now turn off the LED for another 200ms
        output_low(PORTB, LED2);
        _delay_ms(999);
        // start all over again from the top of the loop 
    }
}